import 'package:intl/intl.dart';
import 'package:uuid/uuid.dart';

class Todo {
  String id;

  DateTime taskTime;

  String title;

  String note;

  bool completeFlag; // 是否完成

  String collectId;

  Todo({this.id, this.taskTime, this.title, this.note, this.collectId, this.completeFlag = false}) {

    id = id == null ? Uuid().v4().replaceAll("-", "") : id;
  }

  static Todo fromMap(Map<String, dynamic> map) {
    return Todo(
      id: map["id"],
      taskTime: DateTime.fromMillisecondsSinceEpoch(map["taskTime"]),
      title: map["title"],
      note: map["note"],
      collectId: map["collectId"]
    );
  }

  String get taskTimeToLocal =>  DateFormat('HH:mm').format(taskTime);

  @override
  String toString() {
    return 'Todo{id: $id, taskTime: $taskTime, title: $title, note: $note, completeFlag: $completeFlag, collectId: $collectId}';
  }

}

void main() {
  List<Todo> list = List.generate(5, (i) => Todo(id: i.toString()));
  print("list: ${list}");

  list.forEach((f) {
    f.id = f.id + "111";
  });

  print("list: ${list}");
}
